using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

public class FoodPool : MonoBehaviour
{
    public ObjectPool<GameObject> pool;
    public static FoodPool ins;
    private void Awake()
    {
        ins=this;
        pool=new ObjectPool<GameObject>(CreateFunc,ActionOnGet,ACtionOnRelease,ActionOnDestory,true,100,100000);
    }

    private void ActionOnDestory(GameObject obj)
    {
        Destroy(obj);
    }

    private void ACtionOnRelease(GameObject obj)
    {
        obj.SetActive(false);
    }

    private void ActionOnGet(GameObject obj)
    {
        obj.SetActive(true);
    }

    private GameObject CreateFunc()
    {
        GameObject food=Instantiate(Resources.Load<GameObject>("food"),transform);
        food.GetComponent<Food>().pool=pool;
        return food;
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }
    

    // Update is called once per frame
    void Update()
    {
        
    }
}
